package com.qf.smsplatform.webmaster.service.api;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@FeignClient(value = "SMS-PLATFORM-CACHE", fallback = CacheServiceFallback.class)
public interface CacheService {

    @RequestMapping(value = "/cache/get/{key}", method = RequestMethod.GET)
    String get(@PathVariable("key") String key);
    
    @RequestMapping(value = "/cache/get-object/{key}", method = RequestMethod.GET)
    Object getObject(@PathVariable("key") String key);

    @RequestMapping(value = "/cache/delete", method = RequestMethod.POST)
    boolean del(@RequestParam("keys") String... keys);

    @RequestMapping(value = "/cache/hmset/{key}", method = RequestMethod.POST)
    boolean hMSet(@PathVariable("key") String key, @RequestBody Map map);


    // hgetall  key  -> field,value
    // hmget key field,field,filed -> value,value,value
    @RequestMapping(value = "/cache/hmget/{key}", method = RequestMethod.GET)
    public Map hMGet(@PathVariable("key") String key);

    @RequestMapping(value = "/cache/save2cache", method = RequestMethod.POST)
    void set(@RequestParam("key") String key, @RequestParam("value") String value, @RequestParam("expireSecond") Long expireSecond);

    @RequestMapping(value = "/cache/save2cache-persist", method = RequestMethod.POST)
    void saveCache(@RequestParam("key") String key, @RequestParam("value") String value);

    @RequestMapping(value = "/cache/incr", method = RequestMethod.GET)
    public Long incr(@RequestParam("key") String key, @RequestParam("delta") long delta);

    /**
     * 批量添加操作
     * @param map
     * @return
     */
    @PostMapping("/cache/pipelined/set")
    public boolean MultiSet(@RequestBody Map map);

    /**
     * 添加数据到Redis的set结构中
     * @param key
     * @param map
     */
    @PostMapping("/cache/sadd/{key}")
    void sadd(@PathVariable String key, @RequestBody Map map);
}
